import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:ecy_app_flutter/routes/login/common/DateUtil.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../EcyRouter.dart';
import '../../../constant/color_constant.dart';
import '../../../ecycommon/EcyRequestBaseManager.dart';
import '../../../ecycommon/utils/EcyLogger.dart';
import '../../../ecycommon/utils/EcyUserUtil.dart';
import '../../../model/EcyApiCommonResponse.dart';

class EcyAboutGoodsQiPage extends StatefulWidget {
  const EcyAboutGoodsQiPage({required super.key});

  @override
  State<StatefulWidget> createState() => _EcyAboutGoodsQiPageState();
}

class _EcyAboutGoodsQiPageState extends State<EcyAboutGoodsQiPage>
    with SingleTickerProviderStateMixin {
  _EcyAboutGoodsQiPageState();

  final ScrollController _scrollController = ScrollController();
  bool checked = false;
  bool loadingFlag = false;
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: Colors.white,
        leadingWidth: 50.w,
        leading: GestureDetector(
          behavior: HitTestBehavior.translucent,
          onTap: () {
            EcyRouter.pop(context, "");
          },
          child: Align(
            alignment: Alignment.centerRight,
            child: Image.asset(
              "assets/images/ic_back.png",
              width: 30.w,
            ),
          ),
        ),
        titleSpacing: 0,
        title: const Text('关于有谷气',
            style: TextStyle(
                fontFamily: "PingFang SC",
                fontWeight: FontWeight.w700,
                fontSize: 16,
                color: Color(0xFF262626))),
        centerTitle: true,
      ),
      body: Container(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          color: const Color(0xFFF5F5F5),
          child: SingleChildScrollView(
            controller: _scrollController,
            child: Padding(
              padding: const EdgeInsets.all(8),
              child: Column(
                // spacing: 8,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  const Padding(
                    padding: EdgeInsets.only(bottom: 8),
                  ),
                  Text(
                    '有谷气',
                    textAlign: TextAlign.justify,
                    style: TextStyle(
                        fontFamily: "PingFang SC",
                        fontWeight: FontWeight.w700,
                        fontSize: 16.sp,
                        color: const Color(0xFFa0522d)),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(8),
                    child: SizedBox(
                      height: 100.w,
                      width: 100.w,
                      child: Image.asset("assets/images/app_icon.png"),
                    ),
                  ),
                  Card(
                    color: Colors.white,
                    elevation: 0,
                    margin: const EdgeInsets.only(top: 8, bottom: 2),
                    child: ListTile(
                      title: const Text('用户协议'),
                      trailing: const Icon(
                        Icons.arrow_forward_ios,
                        size: 14,
                      ),
                      splashColor: Colors.transparent,
                      onTap: () {
                        EcyRouter.push(context, EcyRouter.privacyPolicyPage, {
                          "url":
                              "https://www.goodsqi.com/userAgreement/userAgreement.htm",
                          "title": "用户协议"
                        });
                      },
                    ),
                  ),
                  Card(
                    color: Colors.white,
                    elevation: 0,
                    margin: const EdgeInsets.only(bottom: 2),
                    child: ListTile(
                      title: const Text('隐私政策'),
                      trailing: const Icon(Icons.arrow_forward_ios, size: 14),
                      splashColor: Colors.transparent,
                      onTap: () {
                        EcyRouter.push(context, EcyRouter.privacyPolicyPage, {
                          "url":
                              "https://www.goodsqi.com/privacyPolicy/privacyPolicy.html",
                          "title": "隐私政策"
                        });
                      },
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(
                      top: 10,
                    ),
                    child: Text("Copyright©2024-${DateTime.now().year}",
                        style: TextStyle(
                            fontFamily: "PingFang SC",
                            fontSize: 15.sp,
                            color: const Color(0xFF8C8C8C))),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(
                      top: 0,
                    ),
                    child: Text("深圳市鲁米宝贝企业管理有限公司 版权所有",
                        style: TextStyle(
                            fontFamily: "PingFang SC",
                            fontSize: 15.sp,
                            color: const Color(0xFF8C8C8C))),
                  )
                ],
              ),
            ),
          )),
    );
  }

  // 弹出对话框
  Future<bool?> showConfirmDialog(String content) {
    return showDialog<bool>(
      context: context,
      builder: (context) {
        return AlertDialog(
          // title: const Text(''),
          contentPadding: const EdgeInsets.all(0),
          backgroundColor: Colors.white,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(8.0),
          ),
          content: SizedBox(
            height: 130,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Padding(
                  padding: const EdgeInsets.only(top: 20, bottom: 30),
                  child: Text(
                    content,
                    style: const TextStyle(fontSize: 18),
                  ),
                ),
                const Divider(height: 0, color: Color(0XFFdcdcdc)),
                SizedBox(
                  height: 50,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Expanded(
                        flex: 1,
                        child: DecoratedBox(
                          decoration: const BoxDecoration(
                              border: Border(
                            right: BorderSide(
                              width: 1.0,
                              color: Color(0XFFdcdcdc),
                            ),
                          )),
                          child: TextButton(
                            style: const ButtonStyle(
                              alignment: Alignment.center,
                            ),
                            child: const Text(
                              '取消',
                              style:
                                  TextStyle(fontSize: 18, color: Colors.black),
                            ),
                            onPressed: () =>
                                Navigator.of(context).pop(), // 关闭对话框
                          ),
                        ),
                      ),
                      Expanded(
                        flex: 1,
                        child: TextButton(
                          child: const Text(
                            '确定',
                            style: TextStyle(
                                fontSize: 18, color: Color(0xFFEA4B9B)),
                          ),
                          onPressed: () {
                            //关闭对话框并返回true
                            Navigator.of(context).pop(true);
                          },
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          actionsAlignment: MainAxisAlignment.spaceAround,
          actionsPadding: const EdgeInsets.all(0),
        );
      },
    );
  }

  @override
  void dispose() {
    super.dispose();
    _scrollController.dispose();
    _controller.dispose();
  }

  @override
  void deactivate() {
    super.deactivate();
  }
}
